from threading import Thread, Lock
import threading
import time
# 创建锁对象
lock_obj = Lock()
# 车票
ticket = 50
def sale_tacket():
    global ticket
    # 每个窗口有100人
    for i in range(100):
        # 上锁
        lock_obj.acquire()
        if ticket > 0:
            print(f"{threading.current_thread().name}正在售票：{ticket}")
            ticket -= 1
            time.sleep(1)
        # 释放锁
        lock_obj.release()
if __name__ == '__main__':
    for i in range(3):
        t = Thread(target=sale_tacket)
        t.start()